import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
let hintTimer = null
export default new Vuex.Store({
  state: {
    isLogin: false,
    userinfo: null,
    hint:{
      icon: '',
      title: '',
      isShow: false
    },
    loading: {
      title: '正在加载',
      isShow: false
    },
    confirm: null,
    articleClassify: ['科技','IT','人文','社会','教育','其他'],
  },
  mutations: {
    showHint(state,obj){
      state.hint = {...obj}
    },
    showLoading(state,str){
      state.loading = {
        title: str,
        isShow: true
      }
    },
    hideLoading(state){
      state.loading.isShow = false
    },
    showConfirm(state,data){
      state.confirm = sessionStorage.getItem('inviteConfirm') ? null : data
    },
    hideConfirm(state){
      state.confirm = null
    },
    getUserInfo(state,obj){
      state.userinfo = {...obj}
      state.isLogin = true
    },
    exitLogin(state){
      state.isLogin = false
      state.userinfo = null
    }
  },
  actions: {
    showHint(context,obj){
      let hint = {
        title: obj.title,
        icon: obj.isFlag,
        isShow: false
      }
      context.commit('showHint',hint)
      clearTimeout(hintTimer)
      hint.isShow = true
      context.commit('showHint',hint)
      hintTimer = setTimeout(() => {
        hint.isShow = false,
        context.commit('showHint',hint)
      }, 1500)
    },
  },
  modules: {
  }
})
